package com.example.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.beans.PaperAdavice;
import com.example.beans.PaperAdvice1;
import com.example.myapplication.R;
import com.github.siyamed.shapeimageview.CircularImageView;
import com.lidroid.xutils.BitmapUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/30.
 */
public class PaperAdviceAdapter1 extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private LayoutInflater inflater;
    private List<PaperAdvice1> list = new ArrayList<>();
    private BitmapUtils bitmapUtils;


    public PaperAdviceAdapter1(Context context, List<PaperAdvice1> list) {
        inflater = LayoutInflater.from(context);
        this.context = context;
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_advice_second, parent, false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        bitmapUtils = new BitmapUtils(context);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {

        if (list.get(position).getTag() == null) {

        } else {

            boolean b = list.get(position).getTAG();
            if (b) {
                ((MyViewHolder) holder).user_name.setText(list.get(position).getStudent_name());
                ((MyViewHolder) holder).text_content.setText(list.get(position).getAdvice_commit());
                String url = list.get(position).getStudent_pic();
                Log.i("student_pic", url);
                if (url.charAt(0) == '.') {
                    url = url.substring(1);
                }
                bitmapUtils.display(((MyViewHolder) holder).circularImageView, "http://192.168.191.1/app/pic" + url);


            } else {
                ((MyViewHolder) holder).user_name.setText(list.get(position).getTeacher_name());
                ((MyViewHolder) holder).text_content.setText(list.get(position).getAdvice_commit());
                ((MyViewHolder) holder).user_name.setTextColor(Color.RED);
                String url = list.get(position).getTeacher_pic();
                Log.i("teacher_pic", url);
                if (url.charAt(0) == '.') {
                    url = url.substring(1);
                }
                bitmapUtils.display(((MyViewHolder) holder).circularImageView, "http://192.168.191.1/app/pic" + url);
            }
            ((MyViewHolder) holder).time.setText(list.get(position).getAdvice_date());


        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    public class MyViewHolder extends RecyclerView.ViewHolder {
        public CircularImageView circularImageView;
        public TextView user_name, time;
        public Button btn_reply;
        public TextView text_content;

        public MyViewHolder(View itemView) {
            super(itemView);
            circularImageView = (CircularImageView) itemView.findViewById(R.id.circularImageView);
            user_name = (TextView) itemView.findViewById(R.id.user_name);
            time = (TextView) itemView.findViewById(R.id.time);
            text_content = (TextView) itemView.findViewById(R.id.text_content);

        }
    }
}